package com.kingdee.pda.ui.popupwindow;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;

import com.kingdee.pda.R;

/**
 * 扫码视图高度设置悬浮框
 * Created by zhanlg
 * DATE 2020/9/25
 * TIME 9:06
 */
public class ScanViewHeightSettingPpWindow extends PopupWindow implements View.OnClickListener {

    private Context mContext;
    private OnScanViewHeightSelectedListener mListener;


    public ScanViewHeightSettingPpWindow(Context context, OnScanViewHeightSelectedListener listener) {
        super(context);
        this.mContext = context;
        mListener = listener;
        initLayout();
    }

    private void initLayout() {
        setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
        setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        View contentView = LayoutInflater.from(mContext).inflate(R.layout.popupwindow_scan_view_height_setting, null);
//        setBackgroundDrawable(mContext.getResources().getDrawable(R.mipmap.popup_margin_shade_centre));
        setContentView(contentView);
        setOutsideTouchable(true);

        initView(contentView);
    }

    private void initView(View view) {
        view.findViewById(R.id.tv_height_100).setOnClickListener(this);
        view.findViewById(R.id.tv_height_120).setOnClickListener(this);
        view.findViewById(R.id.tv_height_150).setOnClickListener(this);
        view.findViewById(R.id.tv_height_180).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_height_100:
                settingAndCallback(100);
                break;
            case R.id.tv_height_120:
                settingAndCallback(120);
                break;
            case R.id.tv_height_150:
                settingAndCallback(150);
                break;
            case R.id.tv_height_180:
                settingAndCallback(180);
                break;
        }
        dismiss();
    }

    private void settingAndCallback(int height) {
        if (mListener != null) {
            mListener.onHeightSelected(height);
        }
    }


    public interface OnScanViewHeightSelectedListener {
        void onHeightSelected(int height);
    }
}
